home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Examples / Text / Textension / Include / ObjectsRanges.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-21  |  4.8 KB  |  181 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        ObjectsRanges.h
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Written by:    Essam Zaky
  7.  
  8.     Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <2>      1/4/94    EZ        clean up
  13.          <1>      1/4/94    EZ        first checked in
  14.  
  15. */
  16.  
  17. #ifndef _ObjectsRanges_
  18. #define _ObjectsRanges_
  19.  
  20. #ifndef _ToolBoxDump_
  21. #include "ToolBoxDump.h"
  22. #endif
  23.  
  24. #ifndef _TextensionCommon_
  25. #include "TextensionCommon.h"
  26. #endif
  27.  
  28. #ifndef _Array_
  29. #include "Array.h"
  30. #endif
  31.  
  32. #ifndef _AttrObject_
  33. #include "AttrObject.h"
  34. #endif
  35.  
  36. //***************************************************************************************************
  37.  
  38.  
  39. struct TSectRanges {
  40.     long leadIndex; //range index
  41.     long leadCount; //count of range elements in the first range that are not inside
  42.     long leadSectCount; //count of range elements in the first range that are inside
  43.     
  44.     long insideIndex; //range index
  45.     long insideCount; //ranges count
  46.     
  47.     long trailIndex; //range index
  48.     long trailCount; //count of range elements in the last range that are not inside
  49.     long trailSectCount; //count of range elements in the last range that are inside
  50. };
  51. //***************************************************************************************************
  52.  
  53.  
  54. class CRanges    : public CLongTagArray {
  55. public :
  56. //------
  57.     CRanges();
  58.     
  59.     inline void IRanges(short elementSize, short moreElements = 1)
  60.         {this->IArray(elementSize, moreElements);}
  61.     
  62.     virtual void FreeData(Boolean compact = true);
  63.  
  64.     long GetRangeEnd(long rangeIndex) const;
  65.     long GetRangeStart(long rangeIndex) const;
  66.     long GetRangeLen(long rangeIndex) const;
  67.     
  68.     void SetRangeEnd(long rangeIndex, long newEnd);
  69.     
  70.     void GetRangeBounds(long rangeIndex, TOffsetPair* bounds) const;
  71.     
  72.     inline Boolean IsRangeEmpty(long rangeIndex) const {return this->GetRangeLen(rangeIndex) == 0;}
  73.     
  74.     Boolean IsRangeStart(long offset, long rangeIndex = -1) const;
  75.  
  76.     long GetLastRangeEnd() const;
  77.     
  78.     long Offset2RangeIndex(TOffset rangeOffset) const;
  79.     
  80.     void OffsetRanges(long valToAdd, long firstIndex, long count = -1);
  81.     //count < 0 ==> offset up to last range
  82.     
  83.     long SectRanges(long offset, long count, TSectRanges* sectInfo) const;
  84.     
  85.     
  86.     #ifdef txtnDebug
  87.     virtual void CheckCoherence(long count);
  88.     #endif
  89.     
  90.     
  91. protected :
  92. //---------
  93.  
  94. private:
  95. //------
  96. };
  97. //***************************************************************************************************
  98.  
  99.  
  100. class CObjectsRanges : public CRanges {
  101. public :
  102. //------
  103.     CObjectsRanges();
  104.     
  105.     void IObjectsRanges(CAttrObject* continuousObj, short moreElements = 1);
  106.     
  107.     //•override
  108.     virtual void Free();
  109.     virtual void FreeData(Boolean compact = true);
  110.  
  111.     virtual long RemoveElements(long removeIndex, long countToRemove);
  112.     //returns the new elements count
  113.     
  114.     //•own
  115.     virtual CAttrObject* Offset2Object(TOffset offset);
  116.  
  117.     CAttrObject* RangeIndex2Object(short rangeIndex) const;
  118.  
  119.     short GetNextObjectRange(long offset, CAttrObject** theObj, long* rangeLen) const;
  120.     // returns the range index, -1 if no next
  121.     
  122.     OSErr ReplaceRange(long offset, long oldLen, long newLen
  123.                                         , CAttrObject* theObject = nil, Boolean takeObjectCopy =true);
  124.     /*
  125.         -if oldLen == 0 ==> acts as Insert
  126.         -if newLen == 0 ==> acts a delete, in this case "theObject" is not used
  127.         -if theObject is nil the object at "offset" is used
  128.     */
  129.     
  130.     OSErr ReplaceRange(long offset, long oldLen, CObjectsRanges* newRanges, Boolean plug = false);
  131.  
  132.     OSErr InsertObjectRange(short insertIndex, long rangeEnd, CAttrObject* rangeObj, Boolean reference);
  133.     
  134.     virtual long UpdateRangeObjects(long startOffset, long len, const TAttrObjModifier* modifier);
  135.  
  136.     virtual CAttrObject* GetContinuousObj(long startOffset, long len);
  137.  
  138.     inline short CountRanges() const {return this->CountElements();}
  139.     
  140.     inline void SetFreeObjects(char free) {fFreeObjects = free;}
  141.     
  142.     #ifdef txtnDebug
  143.     short CountUniqueObjects();
  144.     virtual void CheckCoherence(long count);
  145.     #endif
  146.     
  147.     
  148. protected :
  149. //---------
  150. CAttrObject*        fContinuousObj;
  151.  
  152. private:
  153. //------
  154. long fLastContStart; //-1 ==> GetContinuousObj will recalc fContinuousObj
  155. long fLastContLen;
  156.  
  157. CAttrObject* fLastSearchedObj;
  158. char fFreeObjects;
  159.  
  160.     CAttrObject* MapObject(CAttrObject* newObj, Boolean takeObjectCopy, Boolean* reference);
  161.     CAttrObject* SearchObject(const CAttrObject* objToCheck);
  162.     
  163.     void SetObjectRange(short rangeIndex, long newRangeEnd, CAttrObject* newObj, Boolean reference);
  164.     
  165.     void ReplaceRangeObj(long offset, long len, CAttrObject* newObj, Boolean reference);
  166.             
  167.     Boolean UpdateRangesBounds(long startOffset, long endOffset, CAttrObject* newObj
  168.                                                             , short* firstRange, short* lastRange);    
  169.     
  170.     
  171.     void ClearRange(long offset, long len);
  172.     
  173.     void FreeObjects(short firstIndex = 0, short lastIndex = -1);
  174.     //frees the objects in the range firstIndex..lastIndex inclusive
  175.     //no params ==> free all objects
  176. };
  177. //***************************************************************************************************
  178.  
  179.  
  180. #endif
  181.